package com.hmyuan.webdesktop.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hmyuan.webdesktop.domain.Filetype;
import com.hmyuan.webdesktop.service.FiletypeService;
import com.hmyuan.webdesktop.util.UserUtil;

@RestController
@RequestMapping("/filetype")
public class FiletypeController {
	@Resource
	private FiletypeService filetypeService;

	@RequestMapping("findList")
	public Map<String, Object> findList(HttpServletRequest rq, HttpServletResponse rp) {

		Map<String, Object> result = new HashMap<String, Object>();

		Filetype filetype = new Filetype();
		List<Filetype> list = filetypeService.findList(filetype);
		result.put("code", 0);
		result.put("msg", "查询成功！");
		result.put("data", list);
		return result;
	}

	@RequestMapping("update")
	public Map<String, Object> update(HttpServletRequest rq, HttpServletResponse rp, Filetype filetype) {
		Map<String, Object> result = new HashMap<String, Object>();
		if (filetype.getId() == null) {
			result.put("code", 1);
			result.put("msg", "更新失败！请刷新页面重试！");
		}

		filetypeService.update(filetype);

		result.put("code", 0);
		result.put("msg", "更新成功！");
		return result;
	}

	@RequestMapping("save")
	public Map<String, Object> save(HttpServletRequest rq, HttpServletResponse rp, Filetype filetype) {
		Map<String, Object> result = new HashMap<String, Object>();
		filetypeService.save(filetype);

		result.put("code", 0);
		result.put("msg", "更新成功！");
		return result;
	}

	@RequestMapping("delete")
	public Map<String, Object> delete(HttpServletRequest rq, HttpServletResponse rp, Integer id) {
		Map<String, Object> result = new HashMap<String, Object>();
		filetypeService.deleteById(id);

		result.put("code", 0);
		result.put("msg", "更新成功！");
		return result;
	}
}
